<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
require_once("Writer.php");
//Includes
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtinputvalidator.inc.php");
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("buttons.inc.php");
use_unit("components4phpfull/jtiframe.inc.php");
use_unit("platinumgrid/jtplatinumgrid.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Vehicle_List2 extends Page
{
       public $JsDisableDiv = null;
       public $hfSetPrefix = null;
       public $JTDivInfo = null;
       public $JTGroupBox5 = null;
       public $Image5 = null;
       public $Label2 = null;
       public $Image3 = null;
       public $Label1 = null;
       public $Label13 = null;
       public $imgInfo = null;
       public $imgNext = null;
       public $imgBack = null;
       public $btnSearch = null;
       public $edtSearch = null;
       public $Image4 = null;
       public $JSDelete = null;
       public $JTJavaScript1 = null;
       public $Image2 = null;
       public $JTPlatinumVehicleList = null;
       public $hiddenVeh = null;
       public $Image1 = null;
       public $JTSiteTheme1 = null;
       function imgInfoJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
        document.getElementById('JTDivInfo').Show();
       <?php

       }

       function imgNextJSClick($sender, $params)
       {

       ?>
       //var answer = confirm("Proceed to next step?");
	     //if(answer)
       //{
		    window.location.href = "set_company_workorders.php";
		   //}
       <?php

       }
       function imgNextJSMouseOut($sender, $params)
       {

       ?>
       document.images['imgNext'].src = 'image/btn_next.png';
       <?php

       }

       function imgNextJSMouseOver($sender, $params)
       {

       ?>
       document.images['imgNext'].src = 'image/btn_next2.png';
       <?php

       }

       function imgBackJSClick($sender, $params)
       {

       ?>
       window.location.href = "set_template_list.php";

       <?php

       }

       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       document.images['imgBack'].src = 'image/btn_back1.png';
       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       document.images['imgBack'].src = 'image/btn_back21.png';
       <?php

       }

       function btnNextJSClick($sender, $params)
       {

       ?>
       var answer = confirm("Proceed to next step?");
	     if(answer)
       {
		    window.location.href = "set_vendor_list.php";
		   }
       <?php

       }



       function Image1JSClick($sender, $params)
       {

       ?>
       var win_height = 450;
       var win_width = 967;
       var height = window.opener.outerHeight;
       var width = window.opener.outerWidth;
       var top = Math.round((height-win_height)/2);
       var left = Math.round((width-win_width)/2);
       window.open('set_vehicle_create.php','vehicle_create_window','location=no,height='+win_height+',width='+win_width+',top='+top+',left='+left);
       <?php

       }




       function JTVehicleHiddenShow($sender, $params)
       {
        $comp_id = $_SESSION['company_id'];
        $query_hidden = "select * from vehicle_tbl where company_id='".$comp_id."'";
        $result_hidden = mysql_query($query_hidden)or die(mysql_error());

        $arr = array();
        while($row_hidden = mysql_fetch_array($result_hidden))
          {
            $vehicle_id = $row_hidden['vehicle_id'];

            /*if($this->hiddenVeh->getValue()==$vehicle_id)
            $radio = "<a href=vehicle_list.php?veh=".$vehicle_id."><img src='image/radio_select.png' border></a>";
            else*/
            //$radio = "<a href=vehicle_list.php?veh=".$vehicle_id."><img src='image/radio.png' border></a>";
            $VIN = "<a href=vehicle_edit.php?veh=".$vehicle_id." title='edit vehicle'>".$row['VIN']."</a>";
            $tools2 = "<a href=veh_details.php?veh=".$vehicle_id."><img src='image/details_orange.jpg' title='additional details' no border></a>
            <a href=details_emission.php?veh=".$vehicle_id."><img src='image/inspection_orange.jpg' title='emission/inspection/journal' no border></a>
            <a href=veh_fuel_list.php?veh=".$vehicle_id."><img src='image/fuel_orange.jpg' title='fuel log' no border></a>
            <a href=veh_workorder_list.php?veh=".$vehicle_id."><img src='image/tools_orange.jpg' title='maintenance/work order' no border></a>
            <a href=veh_expense_list.php?veh=".$vehicle_id."><img src='image/expense_orange.jpg' title='payments/fees/expense' no border></a>
            <img onclick=js_delete('".$vehicle_id."'); src='image/delete_orange.jpg' title='delete'>";

            $arr[] = array(
                        'VIN' => $row_hidden['VIN'],
                        'Plate Number' => $row_hidden['veh_num'],
                        'Year' => $row_hidden['year'],
                        'Make' => $row_hidden['manufacturer_name'],
                        'Model' => $row_hidden['model_name'],
                        'Type/Style' => $row_hidden['style_name']
                        );


          }

            $this->JTVehicleHidden->setCellData($arr);


       }

       function btnExportClick($sender, $params)
       {
       $this->JTVehicleHidden->exportGridToXLSDownload('vehicle_list.xls');


       }



       function Vehicle_List2JSLoad($sender, $params)
       {

       ?>
       hfSetPrefix = document.getElementById('hfSetPrefix').value;
       if(hfSetPrefix==0 || hfSetPrefix=='')
       {
        var win_height = 136;
        var win_width = 300;
        var height = window.opener.top.outerHeight;
        var width = window.opener.top.outerWidth;
        var top = Math.round((height-win_height)/2);
        var left = Math.round((width-win_width)/2);
        window.open("set_veh_prefix.php", 'Veh_prefix', 'location=no,height='+win_height+',width='+win_width+',top='+top+',left='+left);

        disableDiv();
       }
       <?php

       }

       function Image1JSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['Image1'].src="image/add_new.png"
       <?php

       }

       function Image1JSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['Image1'].src="image/add_new_blue.png"
       <?php

       }

       function JTPlatinumVehicleList($sender, $params)
       {
        $comp_id = $_SESSION['company_id'];
        $query1 = "select * from vehicle_tbl where company_id='".$comp_id."' and (VIN like '%".$this->edtSearch->Text."%'
        or veh_num like '%".$this->edtSearch->Text."%'
        or year like '%".$this->edtSearch->Text."%'
        or manufacturer_name like '%".$this->edtSearch->Text."%'
        or model_name like '%".$this->edtSearch->Text."%'
        or style_name like '%".$this->edtSearch->Text."%'
        or department like '%".$this->edtSearch->Text."%') order by vehicle_id ASC";
        $result = mysql_query($query1)or die(mysql_error());


        $arr = array();
        while($row = mysql_fetch_array($result))
          {
            $vehicle_id = $row['vehicle_id'];

            //$pic = $row['photo'];

            $photo = "<img src='".$row['photo']."' height='50px' width='50px' title='edit' onclick=js_edit('".$vehicle_id."') style='cursor:pointer' border=2/>";

            /*if($pic=='')
            {
            $photo = "<div align='center'><a href=vehicle_edit.php?veh=".$vehicle_id."><img src=image/no image.png height='50px' width='50px' title='edit'></a></div>";
            }*/



            if($this->hiddenVeh->getValue()==$vehicle_id)
            $radio = "<a href=vehicle_list.php?veh=".$vehicle_id."><img src='image/radio_select.png' border></a>";
            else
            //$radio = "<a href=vehicle_list.php?veh=".$vehicle_id."><img src='image/radio.png' border></a>";
            $VIN = "<a href=vehicle_edit.php?veh=".$vehicle_id." title='edit vehicle'>".$row['veh_num']."</a>";

            $enc_vehicle_id = base64_encode($vehicle_id);

            if($_SESSION['isAdmin']==1)
            {
            $tools2 = "<img onclick=js_delete('".$vehicle_id."'); src='image/delete.png' title='delete' style='cursor:pointer'>";
            }


            if($_SESSION['isAdmin']==0)
            {
            $tools2 = "";
            }


            //<a href=tire_list.php?veh=".$vehicle_id."><img src='image/tire.png' title='tire management' no border></a>

            $img_name = 'img_details'.$vehicle_id;

            $details = "<a href=veh_details.php?veh=".$vehicle_id."><img id='".$img_name."' name='".$img_name."' src='image/add_details.png' title='additional details' border='0'>";
            //$details = "<a href=veh_details.php?veh=".$vehicle_id."><img id='".$img_name."' name='".$img_name."' src='image/add_details.png' title='additional details' border='0' onmouseover=document.getElementById('".$img_name."').src='image/add_details2.png' onmouseout=document.getElementById('".$img_name."').src='image/additional_details.png'></a>";
            //<a href=timely_report.php?veh=".$vehicle_id."><img src='image/reports.png' title='generate reports' no border></a>
            $track = $row['track_by'];

            if($track=='distance')
            {
            $od1 = $row['tracking_value'];
            $od2 = $row['curr_tracking_value'];
            $mileage = $od2;
            $mil = $mileage.'Km';
            }

            if($track=='hours')
            {
            $od1 = $row['start_hours'];
            $od2 = $row['curr_hours'];
            $mileage = $od2;
            $mil = $mileage.'Hours';
            }






            if($_SESSION['isAdmin']==1)
            $vphoto = $photo;
            if($_SESSION['isAdmin']!=1)
            $vphoto = "<div align='center'><img src='".$row['photo']."' height='75px' width='75px' title='edit'></div>";

            $arr[] = array(
                        'Photo' => $vphoto,
                        'Plate Number' => "<font style='text-transform: uppercase;'>".$row['veh_num']."</font>",
                        'Year' => $row['year'],
                        'Make' => $row['manufacturer_name'],
                        'Model' => $row['model_name'],
                        //'Type/Style' => $row['style_name'],
                        'Total Mileage' =>$mil,
                        'Tools' => $tools2
                        );


          }

            $this->JTPlatinumVehicleList->setCellData($arr);



       }

       function edtSearchJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('edtSearch').value = '';

       <?php

       }


       function Vehicle_List2Create($sender, $params)
       {
       $comp_id = $_SESSION['company_id'];
       $veh = $_GET['veh'];
       $this->hiddenVeh->setValue($veh);
       //$this->Image1->setLink('vehicle_create.php?veh='.$veh);

       //$this->JTPlatinumVehicleList->Header=center;

       if($_SESSION['isAdmin']!='1')
       {
        $this->Image1->setVisible(false);
       }

       if($_SESSION['isAdmin']=='1')
       {
        $this->Image1->setVisible(true);
       }
       }

}

global $application;

global $Vehicle_List2;

//Creates the form
$Vehicle_List2=new Vehicle_List2($application);

//Read from resource file
$Vehicle_List2->loadResource(__FILE__);

//Shows the form
$Vehicle_List2->show();

?>